<html>
<head><meta charset="utf-8"><title>json output for all available lints clippy#5385 · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html">json output for all available lints clippy#5385</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212499496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212499496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212499496">(Oct 06 2020 at 23:43)</a>:</h4>
<p>@lnicola asked about printing all of the lints (<a href="https://github.com/rust-lang/rust-clippy/issues/5385#issuecomment-704233618">https://github.com/rust-lang/rust-clippy/issues/5385#issuecomment-704233618</a>). @bnjjj then suggested that a <code>--json</code> flag or similar might make sense to get the lints with their level as a json output: <a href="https://github.com/rust-lang/rust-clippy/pull/6125#issuecomment-704571993">https://github.com/rust-lang/rust-clippy/pull/6125#issuecomment-704571993</a></p>
<p>Should we add such a flag? And if yes, what should it be called?</p>



<a name="212503894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212503894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212503894">(Oct 07 2020 at 00:48)</a>:</h4>
<p>I think in general providing machine-friendly output is a good idea, but I'm not sure about the UI. </p>
<p>rustc has <code>--error-format=json</code> for this and <code>--json</code> for tweaking the output (see <a href="https://doc.rust-lang.org/rustc/json.html">here</a>). Cargo has <code>--message-format=json</code>. If called from <code>cargo-clippy</code>, we could intercept the latter, but the list of lints is printed from the driver which can be called separately.</p>
<p>Having a flag that only affects the list of lints seems a bit ad-hoc to me. IMO we should have something similar to rustc/cargo, which affects all the output. I would go for <code>--message-format=json</code>, and accept that argument from both cargo-clippy and the driver.</p>



<a name="212504843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212504843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212504843">(Oct 07 2020 at 01:05)</a>:</h4>
<p>I would definitely leave the lint printing in the <code>clippy-driver</code> and would not recommend to move it to <code>cargo-clippy</code>.</p>
<p><code>--error-format=json</code> already works on Clippy, since we pass all the args, we don't want/know how to handle through to rustc. Can you think of something else that would be affected by <code>--message-format=json</code>, besides the lint list and the error output?</p>
<p>I'm experimenting with letting rustc also handle <code>-Whelp</code>, so we don't have to deal with that.</p>



<a name="212555532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212555532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212555532">(Oct 07 2020 at 13:10)</a>:</h4>
<blockquote>
<p>I would definitely leave the lint printing in the clippy-driver and would not recommend to move it to cargo-clippy</p>
</blockquote>
<p>Agreed. Ideally we would rely on rustc describing clippy lints and remove the custom printing. The only problem (as pointed in the issue) is that it requires passing in a crate as an argument. Hopefully with the solution you described <a href="https://github.com/rust-lang/rust-clippy/issues/6122#issuecomment-704642424">here</a> that will not be necessary anymore.</p>
<blockquote>
<p>Can you think of something else that would be affected by --message-format=json</p>
</blockquote>
<p>After testing, not really <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> I was afraid of the interactions with cargo's <code>message-format</code>, but I've seen that when you use that rustc output also uses JSON. So I guess we don't have to handle it.</p>
<hr>
<p>About the list of lints in JSON format, it seems rustc only uses JSON for error messages, and the command line arg does not affect describing the lints. If we want both relying on rustc for describing lints and having the in JSON format too, I guess we should try to change it in rustc?</p>



<a name="212556242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212556242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212556242">(Oct 07 2020 at 13:16)</a>:</h4>
<blockquote>
<p>If we want both relying on rustc for describing lints and having the in JSON format too, I guess we should try to change it in rustc?</p>
</blockquote>
<p>Yeah, that would be the cleanest way to do it. I guess we should try to do it that way then. Or leave it to the rust-analyzer folks, if they want to have that feature.</p>
<p>In summary: we don't want to add json lint name output, but rather leave it to rustc. To do this we should let rustc also handle the lint output.</p>



<a name="212617893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/json%20output%20for%20all%20available%20lints%20clippy%235385/near/212617893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/json.20output.20for.20all.20available.20lints.20clippy.235385.html#212617893">(Oct 07 2020 at 20:55)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/77671">https://github.com/rust-lang/rust/pull/77671</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>